<template>
    <transition name="popup-slide">
      <div class="popup-container" v-if="visible" v-bind:style="popupStyle">
        <div class="popup-content">
          {{ content }}
        </div>
      </div>
    </transition>
  </template>
  
  <script>
  export default {
    props: ['x', 'y', 'content', 'visible', 'position'],
    computed: {
      // 根据传入的位置参数计算气泡框的位置
      popupStyle: function() {
        let style = {
          position: 'absolute',
          zIndex: 999
        }
        if (this.position === 'top') {
          style.bottom = window.innerHeight - this.y + 'px'
          style.left = this.x + 'px'
        } else if (this.position === 'bottom') {
          style.left = this.x + 'px'
        } else if (this.position === 'left') {
          style.top = this.y + 'px'
          style.right = window.innerWidth - this.x + 'px'
        } else if (this.position === 'right') {
          style.top = this.y + 'px'
          style.left = this.x + 'px'
        }
        return style
      }
    }
  }
  </script>
  
  <style scoped>
  .popup-content {
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    min-width: 200px;
    max-width: 300px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
  }
  
  .popup-slide-enter-active,
  .popup-slide-leave-active {
    transition: all 0.5s;
  }
  
  .popup-slide-enter,
  .popup-slide-leave-to {
    transform: translateY(-20px);
    opacity: 0;
  }
  </style>
  